package com.medical.data.controller;


import com.medical.data.domain.ProjectData;
import com.medical.data.service.ProjectDataService;
import com.medical.data.utils.Result;
import com.medical.data.vo.FormResultVo;
import com.medical.data.vo.GetProjectVo;
import com.medical.data.vo.ProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/front/project")
@Api(description = "项目管理")
@Slf4j
public class ProjectController {
    @Autowired
    private ProjectDataService projectDataService;

    @ApiOperation("创建项目接口")
    @ApiImplicitParam(name = "ProjectVo", required = true, paramType = "body", dataTypeClass = ProjectVo.class)
    @PostMapping("/createProject")
    public Result createProject(@Validated @RequestBody ProjectVo projectVo) {
        log.info("/front/project/createProject参数========>{}", projectVo);
        projectDataService.createProject(projectVo);
        return Result.ok();
    }

    @ApiOperation("查询项目接口根据用户查询")
    @ApiImplicitParam(name = "GetProjectVo", required = true, paramType = "body", dataTypeClass = GetProjectVo.class)
    @PostMapping("/getProjectByUser")
    public Result getProjectByUser(@Validated @RequestBody(required = false) GetProjectVo getProjectVo) {
        log.info("/front/project/getProjectByUser参数========>{}", getProjectVo);
        Map<String, Object> resultPage = projectDataService.getProjectByUser(getProjectVo);
        return Result.ok().data(resultPage);
    }

    @ApiOperation("查询项目具体信息接口")
//    @ApiImplicitParam(name = "GetProjectDataVo", required = true, paramType = "body", dataTypeClass = GetProjectDataVo.class)
    @PostMapping("/getProjectData/{projectId}")
    public Result getProjectData(@NotBlank(message = "项目id不可为空") @PathVariable String projectId) {
        log.info("/front/project/getProjectData参数========>{}", projectId);
        ProjectData projectData = projectDataService.getProjectDataById(projectId);
        return Result.ok().data("projectData", projectData);
    }

    @ApiOperation("修改项目具体信息接口")
    @PostMapping("/updateProject/{projectId}")
    public Result updateProject(@Validated @RequestBody ProjectVo projectVo, @NotBlank(message = "项目id不可为空") @PathVariable String projectId) {
        log.info("/front/project/updateProject参数========>{}", projectId);
        projectDataService.updateProject(projectVo, projectId);
        return Result.ok();
    }

    @ApiOperation("删除项目接口")
    @ApiImplicitParam(name = "projectId", required = true, paramType = "query", dataTypeClass = String.class)
    @PostMapping("/deleteProject/{projectId}")
    public Result deleteProject(@NotBlank(message = "项目id不可为空") @PathVariable String projectId) {
        log.info("/front/project/deleteProject参数========>{}", projectId);
        projectDataService.deleteProjectById(projectId);
        return Result.ok();
    }

    @ApiOperation("查询共享项目")
    @ApiImplicitParam(name = "GetProjectVo", required = true, paramType = "body", dataTypeClass = GetProjectVo.class)
    @PostMapping("/getShareProject")
    public Result getShareProject(@Validated @RequestBody(required = false) GetProjectVo getProjectVo) {
        log.info("/front/project/getShareProject========>{}", getProjectVo);
        Map<String, Object> resultPage = projectDataService.getShareProject(getProjectVo);
        return Result.ok().data(resultPage);
    }

    @ApiOperation("查询用户所有项目用于项目共享")
    @PostMapping("/getProjects")
    public Result getProjects() {
        log.info("/front/project/getShareProject========>{}");
        List<FormResultVo> result = projectDataService.getProjects();
        return Result.ok().data("data", result);
    }


}

